﻿using System;
using System.Collections.Generic;
using System.Drawing;

using Microsoft.DirectX;

using NGE;

namespace MH.MENU
{
    public class YesNo : Panelbox
    {
        public YesNo(Game g)
            : base(g)
        {
            this.OnPanelboxOpen += new MenuEvent(YesNo_OnPanelboxOpen);
            this.OnPanelboxClose += new MenuEvent(YesNo_OnPanelboxClose);

            Name = "是否";
            BGColor = Color.Gray;

            Location = new Vector3(40, 120, 0);
            Size = new System.Drawing.Size(240, 80);

            label = new Textbox();
            label.Interval = 50;
            label.Location = new Vector3();
            Elements.Add(label);

            bb_yes = new Buttonbox();
            bb_yes.Textbox.Text = "是";
            bb_yes.Location = new Vector3(200, 40, 0);
            bb_yes.OnButtonboxEvent += new MenuEvent(bb_yes_OnButtonboxEvent);

            bb_no = new Buttonbox();
            bb_no.Textbox.Text = "否";
            bb_no.Location = new Vector3(200, 60, 0);
            bb_no.OnButtonboxEvent += new MenuEvent(bb_no_OnButtonboxEvent);

            Buttonboxes.Add(bb_yes);
            Buttonboxes.Add(bb_no);
        }

        void YesNo_OnPanelboxClose(object sender, object arg)
        {
            
        }

        void YesNo_OnPanelboxOpen(object sender, object arg)
        {
            scriptCOM.AS("var menu_return", false);
            if (arg == null)
            {
                return;
            }
            string str = (string)arg;
            label.Text = str;
            //label.Reset();
        }

        void bb_no_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                scriptCOM.AS("var menu_return no\nmenu close", false);
            }
        }


        void bb_yes_OnButtonboxEvent(object sender, object arg)
        {
            ButtonboxState bs = (ButtonboxState)arg;
            if (bs == ButtonboxState.Up)
            {
                scriptCOM.AS("var menu_return yes\nmenu close",false);
            }
        }
        protected override void OnKeyboardEventCode(object sender, int key, KeyboardState ks)
        {
            if (key == game.Option.KeyB)
            {
                return;
            }
            base.OnKeyboardEventCode(sender, key, ks);
        }
        Buttonbox bb_yes;
        Buttonbox bb_no;
        Textbox label;
        SceneComponent sceneCOM
        {
            get
            {
                return ((SceneComponent)game.GetComponent("SceneCOM"));
            }
        }
        ScriptComponent scriptCOM
        {
            get
            {
                return ((ScriptComponent)game.GetComponent("ScriptCOM"));
            }
        }
    }
}
